How do I create a new AnyType[] array?

Posted by cb on Stack Overflow See other posts from Stack Overflow or by cb
Published on 2010-04-19T00:37:11Z Indexed on 2010/04/19 0:43 UTC
Read the original article Hit count: 236

Which is the best practice in this situation? I would like an un-initialized array of the same type and length as the original.

public static <AnyType extends Comparable<? super AnyType>> void someFunction(AnyType[] someArray) {

    AnyType[] anotherArray = (AnyType[]) new Comparable[someArray.length];
     ...or...
    AnyType[] anotherArray = (AnyType[]) new Object[someArray.length];

    ...some other code...
}

Thanks, CB

© Stack Overflow or respective owner

Related posts about java

Related posts about best-practices